//
//  KFWMessageCommentCell.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/1/19.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//

#import "KFWMessageCommentCell.h"
#import "TQStarRatingView.h"
#import "Model_QuestionComments.h"

@implementation KFWMessageCommentCell
@synthesize label_timeLabel;
@synthesize label_nameCommentLab;
@synthesize label_nameLab;
@synthesize label_textLab;
@synthesize imageview_headOne;
@synthesize imageview_headTwo;
@synthesize imageview_textQiPao;
@synthesize imageview_commentQiPao;
@synthesize imageview_medal;
@synthesize tq_fuwu;
@synthesize tq_xiangying;
@synthesize tq_zhuanye;
@synthesize label_fuwu;
@synthesize label_zhuangye;
@synthesize label_xiangying;

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        label_timeLabel = [UIUtils creatLabel];
        label_timeLabel.frame = CGRectMake((MainScreenWidth - 100)/2, 10, 100, 20);
        label_timeLabel.backgroundColor = RGB(230, 230, 230);
        label_timeLabel.font = FontOfSystem(10);
        label_timeLabel.layer.cornerRadius = 4;
        label_timeLabel.textAlignment = NSTextAlignmentCenter;
        label_timeLabel.layer.masksToBounds = YES;
        label_timeLabel.textColor = [UIColor whiteColor];
        [self addSubview:label_timeLabel];
        
        //评星头像
        imageview_headOne = [[UIImageView alloc] init];
        imageview_headOne.frame = CGRectMake(5, 10 + 20 + 10, WidthOfHead, WidthOfHead);
        imageview_headOne.layer.cornerRadius = WidthOfHead/2;
        imageview_headOne.layer.masksToBounds = YES;
        //评星名字
        label_nameCommentLab = [UIUtils creatLabel];
        label_nameCommentLab.frame = CGRectMake(5, 10 + 20 + 10 + WidthOfHead, WidthOfHead, 30);
        label_nameCommentLab.numberOfLines = 2;
        label_nameCommentLab.textAlignment = NSTextAlignmentCenter;
        label_nameCommentLab.font = FontOfSystem(11);
        label_nameCommentLab.textColor = RGB(115, 164, 213);

        //响应速度
        label_xiangying = [UIUtils creatLabel];
        label_xiangying.font = FontOfHelveticaBold(15);
        label_xiangying.text = @"响应速度：";
        label_xiangying.textColor = ColorOfQuestionList;
        label_xiangying.frame = CGRectMake(5 + WidthOfHead + 5 + 15, 10 + 20 + 10 + 10, 75, 20);
        tq_xiangying = [[TQStarRatingView alloc] initWithCustomFrame:CGRectMake(5 + WidthOfHead + 5 + 15 + 75, 10 + 20 + 10 + 10, 120, 18) numberOfStar:5];
        //服务态度
        label_fuwu = [UIUtils creatLabel];
        label_fuwu.font = FontOfHelveticaBold(15);
        label_fuwu.text = @"服务态度：";
        label_fuwu.textColor = ColorOfQuestionList;
        label_fuwu.frame = CGRectMake(5 + WidthOfHead + 5 + 15, tq_xiangying.frame.origin.y + tq_xiangying.frame.size.height + 3, 75, 20);
        
        tq_fuwu = [[TQStarRatingView alloc] initWithCustomFrame:CGRectMake(5 + WidthOfHead + 5 + 15 + 75, label_fuwu.frame.origin.y, 120, 18) numberOfStar:5];
        
        //专业程度
        label_zhuangye = [UIUtils creatLabel];
        label_zhuangye.font = FontOfHelveticaBold(15);
        label_zhuangye.text = @"专业程度：";
        label_zhuangye.textColor = ColorOfQuestionList;
        label_zhuangye.frame = CGRectMake(5 + WidthOfHead + 5 + 15, label_fuwu.frame.origin.y + label_fuwu.frame.size.height + 3, 75, 20);
        tq_zhuanye = [[TQStarRatingView alloc] initWithCustomFrame:CGRectMake(5 + WidthOfHead + 5 + 15 + 75, label_zhuangye.frame.origin.y, 120, 18) numberOfStar:5];
        
        [tq_xiangying setUserInteractionEnabled:NO];
        [tq_fuwu setUserInteractionEnabled:NO];
        [tq_zhuanye setUserInteractionEnabled:NO];

        //评星气泡
        imageview_commentQiPao = [[UIImageView alloc] init];
        imageview_commentQiPao.frame = CGRectMake(5 + WidthOfHead + 5, 10 + 20 + 10, 15 + 75 + 120 + 10, 10*2 + 20*3);
        imageview_commentQiPao.image = [[UIImage imageFileName:@"qipao_zuo.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(35,20,10,20) resizingMode:UIImageResizingModeStretch];
        
        imageview_headTwo = [[UIImageView alloc] init];
        if(label_nameCommentLab.frame.origin.y + label_nameCommentLab.frame.size.height > imageview_commentQiPao.frame.origin.y + imageview_commentQiPao.frame.size.height)
        {
            imageview_headTwo.frame = CGRectMake(5, label_nameCommentLab.frame.origin.y + label_nameCommentLab.frame.size.height + 10, WidthOfHead, WidthOfHead);
        }
        else
        {
            imageview_headTwo.frame = CGRectMake(5, imageview_commentQiPao.frame.origin.y + imageview_commentQiPao.frame.size.height + 10, WidthOfHead, WidthOfHead);
        }
        imageview_headTwo.layer.cornerRadius = WidthOfHead/2;
        imageview_headTwo.layer.masksToBounds = YES;

        label_nameLab = [UIUtils creatLabel];
        label_nameLab.font = FontOfSystem(11);
        label_nameLab.numberOfLines = 2;
        label_nameLab.textAlignment = NSTextAlignmentCenter;
        label_nameLab.frame = CGRectMake(5, imageview_headTwo.frame.origin.y + WidthOfHead, WidthOfHead, 30);
        label_nameLab.textColor = RGB(115, 164, 213);

        label_textLab = [UIUtils creatLabel];
        label_textLab.font = FontOfHelveticaBold(15);
        label_textLab.numberOfLines = 0;
        label_textLab.textColor = ColorOfQuestionList;

        imageview_textQiPao = [[UIImageView alloc] init];
        
        
        imageview_medal = [[UIImageView alloc] init];
        imageview_medal.frame = CGRectMake(5*2+WidthOfHead+15, imageview_headTwo.frame.origin.y + 10, 33, HeightOfMedal);
        
        [self addSubview:label_nameCommentLab];
        [self addSubview:label_nameLab];
        [self addSubview:imageview_headOne];
        [self addSubview:imageview_headTwo];
        [self addSubview:imageview_textQiPao];
        [self addSubview:imageview_commentQiPao];
        
        [self addSubview:label_xiangying];
        [self addSubview:tq_xiangying];

        [self addSubview:label_fuwu];
        [self addSubview:tq_fuwu];

        [self addSubview:label_zhuangye];
        [self addSubview:tq_zhuanye];

        [self addSubview:label_textLab];
        [self addSubview:imageview_medal];

    }
    return self;
}

- (void)frameOfSubViewWithData:(Model_QuestionComments *)qComents;
{
    if (qComents.string_content && qComents.string_content.length > 0) {
        
        //有评论文字
        CGSize textSize = [UIUtils cgrectFor:qComents.string_content withFont:FontOfQuestionList labWidth:WidthMaxOfMessageImage - 15 - 10 - 33 - 5];
        self.label_textLab.frame = CGRectMake(5*2 + WidthOfHead + 15 + 5 + 33, imageview_headTwo.frame.origin.y + 10, textSize.width, textSize.height);
        if (textSize.height > 30) {                         //文字高度大于奖章高度
            self.imageview_textQiPao.frame = CGRectMake(5*2 + WidthOfHead ,imageview_headTwo.frame.origin.y , textSize.width + 15 + 33 + 5 + 10, textSize.height + 10*2);
            self.imageview_textQiPao.image = [[UIImage imageFileName:@"qipao_zuo.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(35,20,10,20) resizingMode:UIImageResizingModeStretch];

        }
        else
        {
            self.imageview_textQiPao.frame = CGRectMake(5*2 + WidthOfHead ,imageview_headTwo.frame.origin.y , textSize.width + 15 + 33 + 5 + 10, HeightOfMedal + 10*2);
            self.imageview_textQiPao.image = [[UIImage imageFileName:@"qipao_zuo.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(35,20,10,20) resizingMode:UIImageResizingModeStretch];

        }
    }
    else
    {
        //无评论文字
        self.label_textLab.frame = CGRectZero;
        self.imageview_textQiPao.frame = CGRectMake(5*2 + WidthOfHead ,imageview_headTwo.frame.origin.y , 15 + 33 + 10, HeightOfMedal + 10*2);
        self.imageview_textQiPao.image = [[UIImage imageFileName:@"qipao_zuo.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(35,20,10,20) resizingMode:UIImageResizingModeStretch];

    }
}

@end
